<div class="page page-current" id="user-changePwd">
    <!-- 标题栏 -->
    <include file="Public:header_back"/>
    <div class="content">
        <div class="list-block">
            <ul>
                <li>
                    <div class="item-content">
                        <div class="item-media"><i class="icon icon-form-password"></i></div>
                        <div class="item-inner">
                            <div class="item-title label">原密码</div>
                            <div class="item-input">
                                <input type="password" placeholder="Password" class="" name="old-password">
                            </div>
                        </div>
                    </div>
                </li>
                <li>
                    <div class="item-content">
                        <div class="item-media"><i class="icon icon-form-password"></i></div>
                        <div class="item-inner">
                            <div class="item-title label">新密码</div>
                            <div class="item-input">
                                <input type="password" placeholder="Password" class="" name="new-password">
                            </div>
                        </div>
                    </div>
                </li>
                <li>
                    <div class="item-content">
                        <div class="item-media"><i class="icon icon-form-password"></i></div>
                        <div class="item-inner">
                            <div class="item-title label">确认密码</div>
                            <div class="item-input">
                                <input type="password" placeholder="Password" class="" name="con-password">
                            </div>
                        </div>
                    </div>
                </li>
            </ul>
        </div>
        <div class="content-block">
            <div class="row">
                <div class="col-50">
                    <a href="#" class="button button-big button-fill button-danger" id="cancelChange">取消</a>
                </div>
                <div class="col-50">
                    <a href="#" class="button button-big button-fill button-success" id="handleChange">提交</a>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $('#user-changePwd #cancelChange').on('click', function () {
        $.router.back()
    });
    $('#user-changePwd #handleChange').on('click', function () {
        var old_password = $('[name="old-password"]').val();
        var new_password = $('[name="new-password"]').val();
        var con_password = $('[name="con-password"]').val();
        if (new_password != con_password) {
            $.alert('两次密码不一致');
            return;
        }
        if (new_password == '') {
            $.alert('新密码不可为空');
            return;
        }
        $.showPreloader('修改中');
        $.post("{:U('handleChange')}",
                {
                    "old_password": old_password,
                    "new_password": new_password
                },
                function (data) {
                    $.hidePreloader();
                    data = $.parseJSON(data);
                    if (data.code == 1) {
                        $.alert('修改成功', function () {
                            window.location.href = "{:U('Login/index')}";
                        });
                    } else {
                        $.alert(data.msg);
                        console.log(data.msg);
                    }
                });
    });
</script>